#ifndef COLLISIONSTRATEGY_H
#define COLLISIONSTRATEGY_H
#include <functional>
#include <unordered_set>
#include "octree.h"
#include "mytimer.h"
#include "function.h"
#include <mutex>
class CollisionStrategy
{
public:
    CollisionStrategy(std::function<void(OctreeNode* ,const Cuboid&)> CollisionOctreeNodeStrategy,\
                      std::function<bool(const std::vector<OctreeNode*>&, const Cuboid&)> CollisionPointStrategy);
    CollisionStrategy(std::function<void(OctreeNode* ,const Cuboid&,std::vector<OctreeNode *> &)> CollisionOctreeNodeStrategy,\
                      std::function<bool(const std::vector<OctreeNode*>& collisionnode, const Cuboid& robot,std::unordered_set<Point*>&)> CollisionPointStrategy);
    ~CollisionStrategy(){};
public:
    void calculateToOnePart(OctreeNode* node,const Cuboid& robot,std::vector<OctreeNode*>& collisionnode,std::unordered_set<Point*>& results); //执行碰撞检测,对单一部件
    bool calculateToOnePart(OctreeNode* node,const Cuboid& robot);
    bool calculateToParts(OctreeNode* node,const std::vector<Cuboid>& robotpart);//执行碰撞检测，对一组部件
    void printResult();                                   //输出执行结果
    void clearResult();                                   //清空结果集
private:
    //三维物体之间的碰撞检测算法
    std::function<void(OctreeNode* ,const Cuboid&)> m_CollisionOctreeNodeStrategy;
    //点和三维物体间的碰撞检测算法
    std::function<bool(const std::vector<OctreeNode*>& collisionnode, const Cuboid& robot)> m_CollisionPointStrategy;

    //三维物体之间的碰撞检测算法
    std::function<void(OctreeNode* ,const Cuboid&,std::vector<OctreeNode *> &)> m_CollisionOctreeNodeStrategyThread;
    //点和三维物体间的碰撞检测算法
    std::function<bool(const std::vector<OctreeNode*>& collisionnode, const Cuboid& robot,std::unordered_set<Point*>&)> m_CollisionPointStrategyThread;

    double m_nodeckecktime;
    double m_pointchecktime;
public:
    std::mutex mut;
};

#endif // COLLISIONSTRATEGY_H
